@echo off
for /f "delims=" %%i in ('dir /a:-d /b /s 31.avi') do ( 
	
	SETLOCAL ENABLEDELAYEDEXPANSION

	set folder=%%~pi
	set folder2=%%~nxi
	set folderNSlam = !folder:~,-4!
	echo !folder:~,-1! 	
	
	echo folder: !folder!
	echo folder2: !folder2!
	
)

	echo folderNSlam: !folderNSlam!